$('document').ready(function(){
    //初始化事件
    initEvent()
})

function initEvent(){
    $('#login').click(function(){

        let username = $('#username').val()

        let password = $('#password').val()

        if(username.length <= 0 || password.length <= 0){
            alert("请填写用户名或密码")

            return
        }

        let data = {
            username,
            password
        }
        data = JSON.stringify(data)
        $.ajax({
            data,
            url: baseUrl + '/login.php',
            type: 'POST',
            success: function(res){
                res = JSON.parse(res)
                
                if(res.code == 200){
                    setSession("user", res.data)

                    location.href="index.html"
                }
                else{
                    alert(res.msg)
                }
            }
        })
    })
}